/**
 * 
 */
package lifeOfAFish.scenegraph.geom;

import lifeOfAFish.scenegraph.*;
import javax.media.opengl.GL;

/**
 * @author Christian Mletzko
 *
 */
public class sgGeomCuboid extends sgGeometry {

	private float[] m_source;
	private float m_length;
	private float m_width;
	private float m_height;
	
	
	public sgGeomCuboid()
	{
		m_length = 1.0f;
	}
	public sgGeomCuboid(float[] source, float length, float height, float width)
	{
		m_source = source;
		m_length = length;
		m_width = width;
		m_height = height;
		
		
	}
	
	private void createCuboid(){
		
		GL gl;
		gl = sgGlobals.gl;
		gl.glBegin(GL.GL_QUADS);

		    //Back Face of Rectangle, Normal facing @ -Z direction
			gl.glNormal3f(0.0f,0.0f,-1.0f);
			gl.glTexCoord2d(0.0f, 0.0f); gl.glVertex3f(m_source[0], m_source[1], m_source[2]-m_length);
			gl.glVertex3f(m_source[0], m_source[1]+ m_height, m_source[2]-m_length);
			gl.glVertex3f(m_source[0]+m_width, m_source[1]+m_height, m_source[2]-m_length);
			gl.glVertex3f(m_source[0]+m_width, m_source[1], m_source[2]-m_length);
				
		    //Front Face of Rectangle, Normal facing @ Z direction
			gl.glNormal3f(0.0f,0.0f,1.0f);
			gl.glVertex3f(m_source[0], m_source[1], m_source[2]);
		    gl.glVertex3f(m_source[0], m_source[1]+m_height, m_source[2]);
		    gl.glVertex3f(m_source[0]+m_width, m_source[1]+m_height, m_source[2]);
		    gl.glVertex3f(m_source[0]+m_width, m_source[1], m_source[2]);
				
		    //Top Face of Rectangle, Normal facing @ Y direction
		    gl.glNormal3f(0.0f,1.0f,0.0f);
		    gl.glVertex3f(m_source[0], m_source[1]+m_height, m_source[2]);
		    gl.glVertex3f(m_source[0], m_source[1]+ m_height, m_source[2]-m_length);
		    gl.glVertex3f(m_source[0]+m_width, m_source[1]+m_height, m_source[2]-m_length);
		    gl.glVertex3f(m_source[0]+m_width, m_source[1]+m_height, m_source[2]);
				
		    //Bottom Face of Rectangle, Normal facing @ -Y direction
		    gl.glNormal3f(0.0f,-1.0f,0.0f);
		    gl.glVertex3f(m_source[0], m_source[1], m_source[2]);
		    gl.glVertex3f(m_source[0], m_source[1], m_source[2]-m_length);
		    gl.glVertex3f(m_source[0]+m_width, m_source[1], m_source[2]-m_length);
		    gl.glVertex3f(m_source[0]+m_width, m_source[1], m_source[2]);

		    //Right Face of Rectangle, Normal facing @ X direction
		    gl.glNormal3f(1.0f,0.0f,0.0f);
		    gl.glVertex3f(m_source[0]+m_width, m_source[1], m_source[2]);
		    gl.glVertex3f(m_source[0]+m_width, m_source[1]+m_height, m_source[2]);
		    gl.glVertex3f(m_source[0]+m_width, m_source[1]+m_height, m_source[2]-m_length);
		    gl.glVertex3f(m_source[0]+m_width, m_source[1], m_source[2]-m_length);

		    //Left Face of Rectangle, Normal facing @ -X direction
		    gl.glNormal3f(-1.0f,0.0f,0.0f);
		    gl.glVertex3f(m_source[0], m_source[1], m_source[2]);
		    gl.glVertex3f(m_source[0], m_source[1]+m_height, m_source[2]);
		    gl.glVertex3f(m_source[0], m_source[1]+ m_height, m_source[2]-m_length);
		    gl.glVertex3f(m_source[0], m_source[1], m_source[2]-m_length);
		    
		    gl.glEnd();
	}
	@Override
	protected void draw() {
		createCuboid();
	}
	/**
	 * Return (local) bounding box
	 */
	public float[] getBoundingBox() {
		float[] bb = {m_source[0], m_source[1], m_source[2],
					  	m_source[0]+m_width, m_source[1]+m_height, m_source[2]+m_length};
		return bb;
	}
}
